<template>
	<div class="table" v-loading.body="loading">
	        <div class="crumbs">
            <el-breadcrumb separator="/">
            	<el-breadcrumb-item :to="{ path: '/testlib' }">真题库</el-breadcrumb-item>
                <el-breadcrumb-item>题目列表</el-breadcrumb-item>
<!--                 <el-breadcrumb-item>基础表格</el-breadcrumb-item> -->
            </el-breadcrumb>
        </div>
        <div class="handle-box">
<!--             <el-button type="success" icon="plus" class="handle-del mr10" @click="create">添加题目</el-button> -->
<!--             <el-button type="warning" icon="upload" class="handle-del mr10" @click="create">导入真题</el-button> -->
<!--             <el-input placeholder="筛选关键词" class="handle-input mr10"></el-input>
            <el-button type="primary" icon="search">搜索</el-button> -->
        </div>
      <el-tabs @tab-click="handleTabClick()" v-model="activeTab" type="border-card">
        <el-tab-pane :label="pi.Title+' ('+(sectionData[pi.Id] || []).length+'/'+pi.Amount+')'" v-for="(pi,pk) in section" :key="pi.Id" :name="pi.Id+''" >
        <el-row>
          <el-col :span="4">
            <div class="grid-content bg-purple">
                <el-button v-if="pi.LibType == 0" type="success" icon="plus" class="handle-del mr10" @click="create">添加题目</el-button>
                <el-button v-if="pi.LibType == 1" type="success" icon="plus" class="handle-del mr10" @click="create_resource">添加材料</el-button>
            </div>
          </el-col>
          <el-col :span="10"><div class="grid-content bg-purple-light">&nbsp;</div></el-col>
          <el-col :span="10"><div class="grid-content bg-purple">&nbsp;</div></el-col>
        </el-row>
        <div style="height:10px"></div>
        <el-card class="box-card" v-for="(oo,kk) in resources" :key="kk" v-if="pi.LibType == 1">
          <div slot="header" class="clearfix">
            <span style="line-height: 36px;" >
              <el-row>
                  <el-col :span="20">
                      <el-tag type="danger">材料题</el-tag>&nbsp;
                  </el-col>
                  <el-col :span="4">
<!--                         <el-button class="right_button" type="primary" size="small" @click="edit(o)">编辑</el-button>
                      <el-button class="right_button2" type="danger" size="small">删除</el-button> -->
                      <el-button-group>
                        <el-button type="success" icon="plus" size="small"  @click="add_resource_item(oo)">添加题目</el-button>
                        <el-button type="primary" icon="edit" size="small"  @click="edit_resource(oo)">材料编辑</el-button>
                        <el-button type="danger" icon="delete" size="small" @click="del_resource(oo)">删除</el-button>
                      </el-button-group>
                  </el-col>
              </el-row>
              <el-row>
               <a v-html="oo.body"></a>
              </el-row>
          </span>
        </div>
         <div class="text item">
            <el-card class="box-card" v-for="(o,k) in resourceData[oo.id]" :key="k">
                <div slot="header" class="clearfix">
                    <span style="line-height: 36px;" >
                      <el-row>
                          <el-col :span="20">
                              <el-tag type="danger">第{{o.ordering}}题</el-tag>&nbsp;
                              <el-tag type="warning">题目分数:{{o.score}}分</el-tag>&nbsp;
                              <el-tag type="primary">考点:{{o.cate_path}} > {{o.pc_title}}</el-tag>
                          </el-col>
                          <el-col :span="4">
        <!--                         <el-button class="right_button" type="primary" size="small" @click="edit(o)">编辑</el-button>
                              <el-button class="right_button2" type="danger" size="small">删除</el-button> -->
                              <el-button-group>
                                <el-button type="primary" icon="edit" size="small"  @click="edit(o)">题目编辑</el-button>
                                <el-button type="danger" icon="delete" size="small" @click="del(o)">删除</el-button>
                              </el-button-group>
                          </el-col>
                      </el-row>
                      <el-row>
                       <a v-html="o.body"></a>
                      </el-row>
                    </span>
                </div>
                 <div class="text item">
          <el-card class="box-card">
              <div slot="header" class="clearfix card-header" >
                  <el-row>
                      <el-col :span="20">
                          <el-tag>答案选项</el-tag>&nbsp;
                          <el-tag type="success">类型:{{typeHash[o.type]}}</el-tag>
                      </el-col>
                      <el-col :span="4">
                          <el-button type="success" icon="plus" size="small" @click="create_aws(o)">添加答案</el-button>
                          <el-button type="warning" icon="edit" size="small" @click="update_analysis(o)">题目解析</el-button>
                      </el-col>
                  </el-row>
              </div>
              <el-table :data="o.answer_data" style="width: 100%" empty-text="暂无数据,请添加答案">
                  <el-table-column label="#" width="50">
                      <template scope="scope">
                          {{String.fromCharCode(scope.$index + 1 + 64)}}
                      </template>
                  </el-table-column>
                  <el-table-column prop="Body" label="答案文本" width="950">
                      <template scope="scope">
                          <span v-html="scope.row.Body"></span>
                      </template>
                  </el-table-column>
                  <el-table-column prop="IsRightAnswer">
                      <template scope="scope">
<!--                                 <el-tag v-if="scope.row.IsRightAnswer=='0'" type="danger">错误答案</el-tag> -->
                          <el-tag v-if="scope.row.IsRightAnswer=='1'" type="success">正确答案</el-tag>
                      </template>
                  </el-table-column>
                  <el-table-column label="操作">
                      <template scope="scope">
                          <el-button-group>
                          <el-button type="primary" icon="edit" size="small" @click="edit_aws(scope.row,o)">答案编辑</el-button>
                          <el-button type="danger" icon="delete" size="small" @click="delete_aws(scope.row)">删除</el-button>
                          </el-button-group>
                      </template>
                  </el-table-column>
              </el-table>
<!--                 <div class="text item" v-for="(ans,ak) in o.answer_data" :key="ak">
              <span v-html="ans.Body"></span>
          </div> -->
            </el-card>
          </div>
            </el-card>
          </div>

        </el-card>
        <el-card class="box-card" v-for="(o,k) in sectionData[pi.Id]" :key="k" v-if="o.pq_cs_test_resource_id == 0">
          <div slot="header" class="clearfix">
            <span style="line-height: 36px;" >
              <el-row>
                  <el-col :span="20">
                      <el-tag type="danger">第{{o.ordering}}题</el-tag>&nbsp;
                      <el-tag type="warning">题目分数:{{o.score}}分</el-tag>&nbsp;
                      <el-tag type="primary">考点:{{o.cate_path}} > {{o.pc_title}}</el-tag>
                  </el-col>
                  <el-col :span="4">
<!--                         <el-button class="right_button" type="primary" size="small" @click="edit(o)">编辑</el-button>
                      <el-button class="right_button2" type="danger" size="small">删除</el-button> -->
                      <el-button-group>
                        <el-button type="primary" icon="edit" size="small"  @click="edit(o)">题目编辑</el-button>
                        <el-button type="danger" icon="delete" size="small" @click="del(o)">删除</el-button>
                      </el-button-group>
                  </el-col>
              </el-row>
              <el-row>
               <a v-html="o.body"></a>
              </el-row>
          </span>
        </div>
        <div class="text item">
          <el-card class="box-card">
              <div slot="header" class="clearfix card-header" >
                  <el-row>
                      <el-col :span="20">
                          <el-tag>答案选项</el-tag>&nbsp;
                          <el-tag type="success">类型:{{typeHash[o.type]}}</el-tag>
                      </el-col>
                      <el-col :span="4">
                          <el-button type="success" icon="plus" size="small" @click="create_aws(o)">添加答案</el-button>
                          <el-button type="warning" icon="edit" size="small" @click="update_analysis(o)">题目解析</el-button>
                      </el-col>
                  </el-row>
              </div>
              <el-table :data="o.answer_data" style="width: 100%" empty-text="暂无数据,请添加答案">
                  <el-table-column label="#" width="50">
                      <template scope="scope">
                          {{String.fromCharCode(scope.$index + 1 + 64)}}
                      </template>
                  </el-table-column>
                  <el-table-column prop="Body" label="答案文本" width="950">
                      <template scope="scope">
                          <span v-html="scope.row.Body"></span>
                      </template>
                  </el-table-column>
                  <el-table-column prop="IsRightAnswer">
                      <template scope="scope">
<!--                                 <el-tag v-if="scope.row.IsRightAnswer=='0'" type="danger">错误答案</el-tag> -->
                          <el-tag v-if="scope.row.IsRightAnswer=='1'" type="success">正确答案</el-tag>
                      </template>
                  </el-table-column>
                  <el-table-column label="操作">
                      <template scope="scope">
                          <el-button-group>
                          <el-button type="primary" icon="edit" size="small" @click="edit_aws(scope.row,o)">答案编辑</el-button>
                          <el-button type="danger" icon="delete" size="small" @click="delete_aws(scope.row)">删除</el-button>
                          </el-button-group>
                      </template>
                  </el-table-column>
              </el-table>
<!--                 <div class="text item" v-for="(ans,ak) in o.answer_data" :key="ak">
              <span v-html="ans.Body"></span>
          </div> -->
            </el-card>
          </div>
        </el-card>
      </el-tab-pane>
    </el-tabs>
		
		<div class="dialog">
            <el-dialog title="基本信息" :visible.sync="isadding" size="full">
              <el-form :model="item" label-position="top">
              <el-row>
                <el-col :span="5">
                    <el-form-item label="题目类型" label-width="80px">
                    <el-select v-model="item.type" placeholder="请选择" size="200px" filterable>
                      <el-option
                        v-for="item in type"
                        :key="item.value"
                        :label="item.title"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="1">
                    &nbsp;
                 </el-col>
                <el-col :span="6">
                    <el-form-item label="所属考点标签" label-width="80px">
                    <el-select v-model="item.tab_category_id" placeholder="请选择" size="200px">
                      <el-option
                        v-for="item in section"
                        :key="item.Id+''"
                        :label="item.Title"
                        :value="item.Id+''">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                                <el-col :span="1">
                    &nbsp;
                 </el-col>
                 <el-col :span="5">
                    <el-form-item label="考点" label-width="80px">
                    <el-select v-model="item.pq_test_point_category_id" placeholder="请选择" size="200px" filterable :disabled="item.type==2">
                      <el-option
                        v-for="item in pointCategories"
                        :key="item.id"
                        :label="item.title"
                        :value="item.id">
                          <span>{{item.prefix}}{{item.title}}</span>
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>

                <el-col :span="1">
                    &nbsp;
                 </el-col>
                <el-col :span="5">
                    <el-form-item label="题目序号" label-width="80px">
                            <el-input v-model="item.ordering" auto-complete="off" :disabled="item.type==2"></el-input>
                    </el-form-item>
                </el-col>
              </el-row>
              <el-row>
              <el-col :span="12">
			     <el-form-item label="题目详情" label-width="80px" >
			        <quill-editor ref="questionEditor"
			                      v-model="item.body"
			                      :options="editorOption">
<!-- 			                      @blur="onEditorBlur($event)"
			                      @focus="onEditorFocus($event)"
			                      @ready="onEditorReady($event)"> -->
			        </quill-editor>
<!-- 			        <div class="html ql-editor" v-html="content"></div> -->
			     </el-form-item>
                 </el-col>
                 <el-col :span="1">
                    &nbsp;
                 </el-col>
                 <el-col :span="11">
                 <el-form-item label="题目解析" label-width="80px">
                    <quill-editor ref="questionEditor"
                                  v-model="item.analysis"

                                  :options="editorOption">
<!--                                  @blur="onEditorBlur($event)"
                                  @focus="onEditorFocus($event)"
                                  @ready="onEditorReady($event)"> -->
                    </quill-editor>
<!--                    <div class="html ql-editor" v-html="content"></div> -->
                 </el-form-item>
                </el-col>
                </el-row>
                <el-form-item label="发布" label-width="80px">
                	<el-radio class="radio" v-model="item.state" label="1">发布</el-radio>
					<el-radio class="radio" v-model="item.state" label="0">不发布</el-radio>
                </el-form-item>
              </el-form>
              <el-row v-show="item.type!=2">
                <el-col :span="24">
<!--                     <el-tag>答案</el-tag> -->
                        <el-button type="success" icon="plus" @click="create_aws(item)">添加答案</el-button>
                </el-col>
              </el-row>
              <div>
                  &nbsp;
              </div>
                <el-table :data="item.answer_data" style="width: 100%" empty-text="暂无数据,请添加答案" v-show="item.type!=2">
                        <el-table-column label="#" width="50">
                            <template scope="scope">
                                {{String.fromCharCode(scope.$index + 1 + 64)}}
                            </template>
                        </el-table-column>
                        <el-table-column prop="Body" label="答案文本" width="950">
                            <template scope="scope">
                                <span v-html="scope.row.Body"></span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="IsRightAnswer">
                            <template scope="scope">
<!--                                 <el-tag v-if="scope.row.IsRightAnswer=='0'" type="danger">错误答案</el-tag> -->
                                <el-tag v-if="scope.row.IsRightAnswer=='1'" type="success">正确答案</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template scope="scope">
                                <el-button-group>
                                <el-button type="primary" icon="edit" size="small" @click="edit_aws(scope.row,o)">编辑</el-button>
                                <el-button type="danger" icon="delete" size="small" @click="delete_aws(scope.row)">删除</el-button>
                                </el-button-group>
                            </template>
                        </el-table-column>
                    </el-table>
              <div slot="footer" class="dialog-footer">
                <el-button @click="isadding = false">取 消</el-button>
                <el-button type="primary" @click="save(true)" v-show="item.id < 1" :disabled="saved">确 定</el-button>
                <el-button type="success" @click="update()" v-show="item.id > 0" :disabled="saved">更 新</el-button>
              </div>
            </el-dialog>
            <el-dialog title="答案信息" :visible.sync="isaddingaws">
                <el-form :model="answer">
                    <el-form-item label="答案详情" label-width="80px">
                        <quill-editor ref="answerEditor"
                                      v-model="answer.body"
                                      :options="awsEditorOption">
                        </quill-editor>
    <!--                    <div class="html ql-editor" v-html="content"></div> -->
                    </el-form-item>
                    <el-form-item label="答案" label-width="80px">
                        <el-radio class="radio" v-model="answer.is_right_answer" label="0">错误</el-radio>
                        <el-radio class="radio" v-model="answer.is_right_answer" label="1">正确</el-radio>
                    </el-form-item>
                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button @click="isaddingaws = false">取 消</el-button>
                    <el-button type="primary" v-show="answer.id < 1" @click="save_aws(true)">确 定</el-button>
                    <el-button type="success" v-show="answer.id > 0" @click="save_aws(false)">更 新</el-button>
                  </div>
                </el-form>
            </el-dialog>
            <el-dialog title="题目解析" :visible.sync="isanalysis">
                <el-form :model="item">
                    <el-form-item label="解析详情" label-width="80px">
                        <quill-editor ref="answerEditor"
                                      v-model="item.analysis"
                                      :options="analysisEditorOption">
                        </quill-editor>
    <!--                    <div class="html ql-editor" v-html="content"></div> -->
                    </el-form-item>
                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button @click="isanalysis = false">取 消</el-button>
                    <el-button type="success" @click="save_analysis()">更 新</el-button>
                  </div>
                </el-form>
            </el-dialog>

            <el-dialog title="材料详情" :visible.sync="isaddingresource" size="small">
              <el-form :model="resource" label-position="top">
                    <el-form-item label="材料详情" label-width="80px">
                        <quill-editor ref="resourceEditor"
                                      v-model="resource.body"
                                      :options="resourceEditorOption">
                        </quill-editor>
    <!--                    <div class="html ql-editor" v-html="content"></div> -->
                    </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="isaddingresource = false">取 消</el-button>
                <el-button type="primary" @click="save_resource(true)" v-show="resource.id < 1">确 定</el-button>
                <el-button type="success" @click="save_resource()" v-show="resource.id > 0">更 新</el-button>
              </div>
            </el-dialog>
        </div>
	</div>
</template>
<script>
    import http from "../../lib/http"
    import tree from "../../lib/tree"
    import "../../assets/main.css"
    export default {
    	data : function(){
    		var params = this.$route.path.split("-")
    		this.library_id = params[1]
    		return {
    			isadding : false,
                isanalysis : false,
                isaddingaws : false,
                isaddingresource : false,
                resources : [],
                resource : {
                  body : "",
                  id : 0
                },
                saved : false,
                tableData : [],
                loading : true,
                activeTab : "",
                pointCategories : [],
                pointRawCategories : [],
                section:[],
                sectionHash : {},
                editorOption : { placeholder : "请输入题目文本"},
                awsEditorOption: {
                  placeholder:"请输入答案",
                  modules: {
                    toolbar: [
                      ['bold', 'italic'],
                      [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                      ['link', 'image']
                    ]
                  }
                },
                analysisEditorOption: {
                  placeholder:"请输入解析",
                  disabled : true,
                  modules: {
                    toolbar: [
                      ['bold', 'italic'],
                      [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                      ['link', 'image']
                    ]
                  }
                },
                resourceEditorOption : {
                  placeholder:"请输入材料详情",
                  disabled : true,
                  modules: {
                    toolbar: [
                      ['bold', 'italic'],
                      [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                      ['link', 'image']
                    ]
                  }
                },
                typeHash : {
                    "0" : "单选",
                    "1" : "多选",
                    "2" : "材料",
                    "3" : "文本",
                    "4" : "不定项"
                },
    			type : [{
    				value : "0",
    				title : "单选"
    			},{
    				value : "1",
    				title : "多选"
    			},{
    				value : "3",
    				title : "文本"
    			},{
    				value : "4",
    				title : "不定项"
    			}],
    			item : {
    				id : 0,
    				pid : 0,
    				type : "0",
    				body : "",
    				state : "1",
                    analysis : "",
    				pq_test_point_category_id : "",
    				pq_cs_test_library_id: params[1],
            pq_cs_test_resource_id : 0
    			}, 
          answer : {
              id : 0,
              pq_cs_test_item_id : 0,
              body : "",
              ordering : 0,
              is_right_answer : "0"
          },               
          pagination : {
              current : 1,
              total : 0,
              size : 1000
          }
    		}
    	},
      computed : {
        sectionData : function(){
          var sd = {}
          for(var i=0,j=this.tableData.length;i<j;i++){
            sd[this.tableData[i]["tab_category_id"]] = sd[this.tableData[i]["tab_category_id"]] || []
            sd[this.tableData[i]["tab_category_id"]][sd[this.tableData[i]["tab_category_id"]].length] = this.tableData[i]
          }
          return sd;
        },
        resourceData : function(){
          var sd = {}
          for(var i=0,j=this.tableData.length;i<j;i++){
            sd[this.tableData[i]["pq_cs_test_resource_id"]] = sd[this.tableData[i]["pq_cs_test_resource_id"]] || []
            sd[this.tableData[i]["pq_cs_test_resource_id"]][sd[this.tableData[i]["pq_cs_test_resource_id"]].length] = this.tableData[i]
          }
          return sd;
        }
      },
    	created : function(){
            var self = this;
            http.get(self,"point_categories",{code:"CS_ROOT"}).then((res) => {
                var response = res.data
                 self.pointRawCategories = response.data
                //console.log(response.data)
                if (response.code == "ok") {
                    self.pointCategories = tree.make(response.data,"pid",response.data[0].pid)
                }
            })
            http.alive(this,function(){
                self.getData();
                http.get(self,"cs_test_libraries/"+self.library_id).then(function(res){
                  http.post(self,"test_category/manage/rensection",{p:res.data.data.point_data}).then(function(res){
                    self.section = res.data
                    self.section.forEach(function(e){
                      self.sectionHash[e.Id] = e.Title
                    })
                    self.section.sort(function(v1,v2){
                      return v1.Ordering < v2.Ordering
                    })
                    self.activeTab = res.data[0].Id + ''
                  })
                })
                self.list_resource()
            })
    	},
        // computed : {
        //     data : function(){
        //         const self = this;
        //         return self.tableData.filter(function(d){
        //             d.answer_data = JSON.parse(d.answer_data)
        //             return d
        //         })
        //     }
        // },
    	methods : {
            handleTabClick : function(){
              //alert(this.activeTab)
            },

            initItem : function(){
                this.item = {
                    id : 0,
                    pid : 0,
                    type : "0",
                    body : "",
                    state : "1",
                    analysis : "",
                    pq_test_point_category_id : "",
                    pq_cs_test_library_id: this.library_id,
                    tab_category_id : this.activeTab
                }
            },
            initanswer : function(){
                this.answer = {
                    id : 0,
                    pq_cs_test_item_id : 0,
                    body : "",
                    ordering : 0,
                    is_right_answer : "0"
                }
            },
            initResource : function(){
                this.resource = {
                  body : "",
                  id : 0,
                  library_id : this.library_id
                }
            },
        		create : function(){
              this.initItem()
        			this.isadding = true      
        		},
            create_resource : function(){
              this.isaddingresource = true
              this.initResource()
            },
            edit_resource : function(o){
              this.isaddingresource = true
              this.resource = JSON.parse(JSON.stringify(o))
            },
            list_resource : function(){
              var self = this
              http.get(this,"cs_test_libraries_item/"+this.library_id+"/resource").then(function(res){
                self.resources = res.data.data
                console.log("aaaaaa")
                console.log(res.data)
              })
            },
            create_aws : function(row){
                this.isaddingaws = true
                this.initanswer()
                this.answer.pq_cs_test_item_id = row.id
            },
            del : function(item){
                var self = this
                this.$confirm('是否确定删除此题目?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                    http.delete(self,"cs_test_libraries_item/"+item.id).then(function(res){
                        self.$notify.success("成功","删除成功!")
                        self.getData()
                    })
                }).catch(() => {
     
                });
            },
            update_analysis : function(row){
                this.isanalysis = true
                this.item = JSON.parse(JSON.stringify(row))
            },
            edit_aws : function(answer,row){
                this.isaddingaws = true
                this.answer.id = answer.Id
                this.answer.pq_cs_test_item_id = answer.PqCsTestItemId
                this.answer.body = answer.Body
                this.answer.is_right_answer = answer.IsRightAnswer+""
                this.answer.pq_cs_test_item_id = row.id
                console.log(this.answer.is_right_answer)
            },

            delete_aws : function(row){
                var self = this
                this.$confirm('是否确定删除此答案?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                    http.delete(self,"cs_test_libraries_item_answer/"+row.Id).then(function(res){
                        if (self.item.id > 0) {
                            http.get(self,"cs_test_libraries_item/"+self.item.id+"/detail").then(function(res){
                                self.item = res.data.data
                                self.item.answer_data = JSON.parse(self.item.answer_data)
                            })
                        }
                        self.getData()
                    })
                }).catch(() => {
     
                });
            },
            add_resource_item : function(o){
              this.initItem()
              this.item.pq_cs_test_resource_id = o.id
              this.isadding = true
            },
            save_resource : function(add){
              var self = this
              return http.post(this,"cs_test_libraries_item/"+this.library_id+"/resource",this.resource).then(function(res){
                if(res.data.code == "ok"){
                  self.$notify.success({
                        title : "成功",
                        message : add ? "添加成功" : "编辑成功"
                    })
                  self.list_resource()
                }
                else{
                  self.$notify.error({
                      title : "错误",
                      message : res.data.msg
                  })
                }
                self.isaddingresource = false
              })
            },
            save_aws : function(add){
                var self = this
                return http.post(this,"cs_test_libraries_item/"+this.library_id+'/answer',this.answer).then((res)=>{
                    self.isaddingaws = false
                    var data = res.data
                    if (data.code == "ok") {
                        self.$notify.success({
                            title : "成功",
                            message : add ? "添加成功" : "编辑成功"
                        })
                        if (self.item.id > 0) {
                            http.get(self,"cs_test_libraries_item/"+self.item.id+"/detail").then(function(res){
                                self.item = res.data.data
                                self.item.answer_data = JSON.parse(self.item.answer_data)
                            })
                        }
                        //this.item.answer_data.push(this.answer)
                        self.getData()
                    }
                    else{
                        self.$notify.error({
                            title : "错误",
                            message : data.msg
                        })
                    }
                })
            },
            edit : function(row){
                this.isadding = true
                this.item = JSON.parse(JSON.stringify(row))
                this.item.tab_category_id = this.activeTab
            },
            update : function(){
                this.save(false)
            },
            getData : function(){
                var self = this;
                this.loading = true
                var params = {
                    skip : (this.pagination.current - 1) * this.pagination.size,
                    limit : this.pagination.size
                }
                http.get(self,"cs_test_libraries_item/"+this.library_id,params).then((res) => {
                    var response = res.data
                    self.loading = false
                    if (response.code == "ok") {
                        console.log(response.data)
                        if (!response.data) {
                            self.tableData = []
                            self.pagination.total = 0
                        }
                        else{
                            self.tableData = response.data
                            for(var i=0,j=self.tableData.length;i<j;i++){
                                if(self.tableData[i].answer_data != ""){
                                    self.tableData[i].answer_data = JSON.parse(self.tableData[i].answer_data)
                                }
                                else{
                                    self.tableData[i].answer_data = []
                                }
                            }
                            self.pagination.total = response.total * 1
                        }
                    }
                    
                    
                })
                
                // if(process.env.NODE_ENV === 'development'){
                //     self.url = '/ms/table/list';
                // };
                // self.$axios.post(self.url, {page:self.cur_page}).then((res) => {
                //     self.tableData = res.data.list;
                // })
            },
            save_analysis : function(){
                //this.item = JSON.parse(JSON.stringify(row))
                this.save()
            },
    	      save : function(add,resource_id){
                var self = this
                this.saved = true
                http.post(this,"cs_test_libraries_item/"+this.library_id,this.item).then((res)=>{
                    self.isadding = false
                    self.isanalysis = false
                    self.saved = false
                    var data = res.data
                    if (data.code == "ok") {
                    	self.$notify.success({
                            title : "成功",
                            message : add ? "添加成功" : "编辑成功"
                        })
                        self.getData()
                    }
                    else{
                        self.$notify.error({
                            title : "错误",
                            message : data.msg
                        })
                    }
                    setTimeout(function(){
                        self.initItem()
                    })
                    
                })
            }
    	}
    }
</script>
<style scoped>
.box-card{
    margin: 0 0 20px 0
}
/*.right_button {
    float:right;
    margin: -65px 65px 20px 0px;
}*/
/*.right_button2{
    float:right;
    margin: -65px 15px 20px 0px;
}*/
</style>